// console.log('ready fuck');

var success = function(r) {
	alert(r.message);
};
var error = function(err) {

};
var ajaxPost = function(url, method, form, success, error) {
	var request = {
		url: url,
		type: method,
		contentType: 'application/json',
		success: function(r) {
			success(r);
		},
		error: function(err) {
			r = {
				success: false,
				data: err
			};
			error(r);
		}
	};
	if (method === 'post') {
		var data = JSON.stringify(form);
		request.data = data;
	}
	$.ajax(request);
};



var postCheck = function() {
	var url = '/center/check_message/all';
	var method = 'post';
	var form = {};
	var success = function(r) {
		if (r.success) {
			if (r.message_not_read) {
				$("#notification-message-all").attr('style', 'display:inline;');
			};
		} else {
			// console.log('no message');
		}
	};
	ajaxPost(url, method, form, success, error);
}



var checkMessage = function() {
    if ($("ul.navbar-right").children().length > 1) {
	    postCheck();
	}
}


if (!location.href.includes('center')) {
	console.log(location.href);
	window.setInterval(checkMessage, 5000)
};



